﻿/**********************************************
 * 功能名称：数据检查
编写人：  杨莹
建立时间： 杨 2008年11月15日
说明：

 **************************************************************/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using System.Threading;

namespace Hisun.View.Calculation
{
    public partial class Execute : AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_Execute_Click(object sender, EventArgs e)
        {

            //该方法实现了一个图标在计算执行的过程中的等待界面。
            //插入

            string CurrentAccountPeriod = Application["accountPeriod"].ToString();

            Response.Write("<div id=xx2  align = center ><img alt='' src='/App_Themes/2011_Blue/Images/Loading.gif' width = 60 height = 60 /><br><font color = red size = 3>正在计算，不要关闭窗口，请等待...</font></div>");
            string MyEmptyString = " ";
            for (int i = 0; i < 300; i++)
            {
                MyEmptyString = MyEmptyString + " ";
            }
            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();

            Response.Write("<div  align = center><br><font color = black size = 2>正在初始化成本计算，请等待...</font></div>");

            db.CommandTimeout = 12000;  //设定计算时间在20分钟以内完成。

            db.初始化成本计算(CurrentAccountPeriod);

          


            Thread.Sleep(2000);
            Response.Write("<div   align = center><br><font color = blue size = 2>完成!</font></div>");
            Response.Write("<div  align = center><br><font color = black size = 2>正在计算作业成本，请等待...</font></div>");
            //Thread.Sleep(5000);
            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();



            db.全部作业成本分配(CurrentAccountPeriod);
            Thread.Sleep(2000);

            var AlertQueryList_1 = from a in db.TABC_PUBLIC_ComputeAlertInfo
                                   join b in db.TABC_JS_CostCenter on a.作业中心ID equals b.作业中心ID
                                   where a.标签ID == 1001
                                   select new
                                   {
                                       a.作业中心ID,
                                       b.作业中心名称,
                                       a.标签

                                   };
            foreach (var AlertQuery_1 in AlertQueryList_1)
            {
                Response.Write("<div align = left ><br><font color = gray size = 2>" + "(" + AlertQuery_1.作业中心ID+")"+AlertQuery_1.作业中心名称 + ":" + AlertQuery_1.标签 + "</font></div>");
                Response.Write(MyEmptyString);//用于填充满256个字节。
                Response.Flush();
            }

            Response.Write("<div  align = center><br><font color = black size = 2>正在计算作业中心直接成本，请等待...</font></div>");
            //Thread.Sleep(5000);
            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();

            db.直接成本计算(CurrentAccountPeriod);
            Thread.Sleep(2000);

            var AlertQueryList_2 = from a in db.TABC_PUBLIC_ComputeAlertInfo
                                   join b in db.TABC_JS_CostCenter on a.作业中心ID equals b.作业中心ID
                                   where a.标签ID == 2001
                                   select new
                                   {
                                       a.作业中心ID,
                                       b.作业中心名称,
                                       a.标签

                                   };
            foreach (var AlertQuery_2 in AlertQueryList_2)
            {
                Response.Write("<div  align = left><br><font color = gray size = 2>" + "(" + AlertQuery_2.作业中心ID+")"+AlertQuery_2.作业中心名称 + ":" + AlertQuery_2.标签 + "</div>");
                Response.Write(MyEmptyString);//用于填充满256个字节。
                Response.Flush();
            }

            db.产品作业成本计算(CurrentAccountPeriod);
            Thread.Sleep(2000);
            Response.Write("<div   align = center><br><font color = blue size = 2>完成!</font></div>");


            Response.Write("<div  align = center><br><font color = black size = 2>正在计算原材料成本，请等待...</font></div>");

            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();


            db.产品原材料计算(CurrentAccountPeriod);
            Thread.Sleep(2000);

            Response.Write("<div   align = center><br><font color = blue size = 2>完成!</font></div>");


            Response.Write("<div  align = center><br><font color = black size = 2>正在计算全部中间体成本，请等待...</font></div>");

            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();
    
            db.全部中间体成本计算(CurrentAccountPeriod);



            db.填充静态报表数据(CurrentAccountPeriod);
            Thread.Sleep(2000);

            Response.Write("<div   align = center><br><font color = blue size = 2>完成!</font></div>");


            Response.Write("<div  align = center><br><font color = black size = 2>正在建立成本报表数据，请等待...</font></div>");

            Response.Write(MyEmptyString);//用于填充满256个字节。
            Response.Flush();

            Response.Write("<div   align = center><br><font color = blue size = 2>完成!</font></div>");
             //db.产品原材料计算(Application["accountPeriod"].ToString());
            Response.Write("<script>document.getElementById('xx2').style.display='none';</script>");
            
 

        }
    }
}
